<?php
class Session{

	public function __construct(){
		setlocale(LC_TIME,'fr_FR.ISO8859-1');
		if(!isset($_SESSION)){
			session_start();
		}
	}

	public function setFlash($message,$type){
		$_SESSION['flash'] = array(
			'message' => $message,
			'type' => $type
		);
	}

	public function flash(){
		 if(isset($_SESSION['flash']['message'])){
		 	$html = '<div style="margin-top:20px" class="alert '.$_SESSION['flash'] ['type'].'"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><p>'.$_SESSION['flash']['message'].'</p></div>'; 
		 	$_SESSION['flash'] = array();
		 	return $html;
		 }
	}

	public function write($key,$value){
		$_SESSION[$key] = $value; 
	}

	public function read($key = null){
		if($key){
			if(isset($_SESSION[$key])){
				return $_SESSION[$key];
			}else{
				return false;
			}
			
		}else{
			return $_SESSION;
		}
	}

	public function isLogged(){
		if (isset($_SESSION['Utilisateur']->id)){
			return $_SESSION['Utilisateur']->id;	
		}
	}
}